# 172.25.254.0/24 - 172.25.254.255/24
import random

set1 = set()
ip_list = {}

# 生成ip地址
with open("ips.txt", "w+") as f:
    for i in range(12000):
        a = random.randint(0, 255)
        str1 = "172.25.254." + str(a)
        set1.add(str1)
        f.write(str1 + " \n")
f.close()

# 计数重复的ip地址
for i in set1:
    ip_list[i] = 0
with open("ips.txt", "r+") as f:
    for i in f:
        ip = i.split(' ')[0]
        if ip in set1:
            ip_list[ip] = ip_list[ip] + 1
f.close()

# 将ip地址排序
ip_list = sorted(ip_list.items(), key=lambda x: x[1],reverse= True)

# 输出
tplt = "{0:^8}\t{1:^8}"
print("重复次数前十".center(20))
print(tplt.format("IP地址","重复次数"))
for i in range(10):
    print(tplt.format(ip_list[i][0],ip_list[i][1]))
